#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<math.h>
#include<gsl/gsl_randist.h>

const unsigned int MAXBIN=100;
const float CI_BAF=.025;
const float CI_RR=.034;
const float HET_RATIO = .3;

using namespace std;

struct sd_t{
  float alpha;
  float mu_baf;
  float mu_rr;
  float sd_val_baf;
  float sd_val_rr;
  vector<float> rawdata_baf;
  vector<float> rawdata_rr;
};

vector<sd_t> sd_vec;

struct feature_t{
  string rs;
  string chr;
  int pos;
  float maf;
  float rr;
};

struct byRR{
  bool operator()(const feature_t & f1, const feature_t & f2) const{
    return(f1.rr<f2.rr);
  }
};

class bin_t{
private:
  vector<feature_t> features;
  set<float> rr_set;
public:
  void add_feature(const feature_t & f);
  feature_t get_feature(int i);
  float get_median();
  int size();
};

void bin_t::add_feature(const feature_t & f){
  features.push_back(f);
  rr_set.insert(f.rr);
}

feature_t bin_t::get_feature(int i){
  try{
    return features.at(i);
  }catch(exception e){
    cerr<<"Could not fetch index "<<i<<endl;
    exit(1);
  }
}

int bin_t::size(){
  return features.size();
}

float bin_t::get_median(){
  int mid = rr_set.size()/2;
  set<float>::iterator it = rr_set.begin();
  for(int i=0;i<mid;++i){
    it++;
  }
  return *it;
}

vector<bin_t> bins;
//float rr_offset = 0;
//float het_weights = 0;
//float grand_sd_baf = 0;
//float grand_sd_rr = 0;


